//==============================================================================
//
//               Copyright (C) 2002  Dick van Oudheusden
//  
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//==============================================================================
// 
//  $Date: 2003-11-27 21:14:09 $ $Revision: 1.1 $
//
//==============================================================================

#include <stdlib.h>

#include "ofc/config.h"

#include "ofc/DCube.h"

#include "DInc.h"
#include "DTest.h"

//-Collections-----------------------------------------------------------------

void DCube_test()
{
  DCube *cube1 = [[DCube alloc] init];
  DCube *cube2 =  [DCube alloc];
  DInc  *test;
  int    r,c,l;
  
  STARTTEST();

  [cube2 init :15 :10 :5];

  TEST( [cube1 isValid :0 :0 :0]);
  TEST(![cube1 isValid :1 :1 :1]);
  
  TEST([cube2 isValid :0  :0 :0]);
  TEST([cube2 isValid :14 :9 :4]);

  TEST(![cube2 isValid :15 :0  :0]);
  TEST(![cube2 isValid :0  :10 :0]);
  TEST(![cube2 isValid :0  :0  :5]);

  TEST([cube2 length ] == 750);
  TEST([cube2 rows   ] == 10 );
  TEST([cube2 columns] == 15 );
  TEST([cube2 layers ] == 5  );
  
  [DInc reset];

  for (c = 0; c < [cube2 columns]; c++)
    for (r = 0; r < [cube2 rows]; r++)
      for (l = 0; l < [cube2 layers]; l++)
      {
        [cube2 set :c :r :l :[DInc new]];
      }

  test = [cube2 get :12 :8 :2];
  
  TEST([test number] == 643); // 12 * (rows * layers) + 8 * (layers) + 2 + 1
  
  TEST([[cube2 columns :20] columns] == 20);
  TEST([[cube2 rows    :15] rows   ] == 15);
  TEST([[cube2 layers  :10] layers ] == 10);
  
  TEST(![cube2 has :[DInc new]]);
  TEST( [cube2 has :test]);

  [cube2 set :18 :14 :5 :test];

  TEST([cube2 count :test] == 2);

  [cube2 set :18 :14 :5 :nil];

  TEST([cube2 count :test] == 1);
  
  [cube2 free];
  [cube1 free];

  STOPTEST();
}

